package com.jishuo.nontax.bfc.service;

import com.github.pagehelper.PageHelper;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.ErrorCodeEnum;
import com.jishuo.base.bean.Pagination;
import com.jishuo.nontax.bean.vo.SumPosVO;
import com.jishuo.nontax.bfc.dao.SumposMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther dinggaofei
 * @Date 2022/12/21 15:20
 */
@Service
public class SumposService {
    @Resource
    private SumposMapper sumposMapper;
    private static Logger logger = LoggerFactory.getLogger(SumposService.class);

    /**
     * @param sumpos
     * @auther dinggaofei
     * @Date 2022/12/21 15:50
     * @description
     */
    public BaseResult setSumPos(SumPosVO sumpos) {
        try {
            if (sumposMapper.findSumPosCount(sumpos.getBankaffirm(), sumpos.getAccountnum(), sumpos.getAccountdate()) > 0) {
                if (sumposMapper.updateSumPos(sumpos) > 0) {
                    return new BaseResult();
                }
            } else {
                if (sumposMapper.insertSumPos(sumpos) > 0) {
                    return new BaseResult();
                }
            }
            return new BaseResult(ErrorCodeEnum.DB_ERR);
        } catch (Exception e) {
            logger.info("处理失败：" + e.toString());
            return new BaseResult(ErrorCodeEnum.UNKNOWN_ERR);
        }
    }

    /**
     * 获得pos列表分页
     * @return
     */
    public List<SumPosVO> findBankPosPage(SumPosVO sumPosVO, Pagination pagination) {
        // 当单页条数大于零时，启用分页
        if (pagination.getRows() > 0) PageHelper.startPage(pagination.getPage(), pagination.getRows());
        return sumposMapper.findBankPosPage(sumPosVO);
    }
}
